﻿--
--
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'spZeusPackageReceive' AND type = 'P')
BEGIN
  DROP PROCEDURE spZeusPackageReceive
END
GO

-- HU - Rakomány átvétel
-- EN - Package receiving
--
CREATE PROCEDURE spZeusPackageReceive
(@AccessToken INTEGER, @SupplyID INTEGER,  @Code NVARCHAR(20), @EAN NVARCHAR(128), @Quantity DECIMAL(18,6), @SupplyItemID INTEGER)
 AS
BEGIN
  DECLARE
    @Err INTEGER,
    @Rows INTEGER,
    @UserID INTEGER,
    @Lang NVARCHAR(10)

  DECLARE
    @ID INTEGER

  EXEC @Err = spAccessTokenCheck @AccessToken, @UserID OUTPUT, @Lang OUTPUT

  IF (@Err != 0)
    GOTO __ERROR__


  IF (ISNULL(@Quantity, 0) <= 0) BEGIN

    IF (@Lang = 'HU')
      RAISERROR (N'Mennyiség nem lehet 0 vagy negatív !', 16, 1)

    IF (@Lang = 'EN')
      RAISERROR (N'Quantity could not benn less than Zero !', 16, 1)

    IF (@Lang = 'DE')
      RAISERROR (N'Menge nicht null oder negativ sein kann !', 16, 1)

    GOTO __ERROR__
  END

  --
  --
  EXEC @Err = spZeusPackageAdd @Lang, @SupplyID, @Code, @Ean, @Quantity, @SupplyItemID

  IF (@Err != 0)
    GOTO __ERROR__


  -- HU - Visszaadja ennek a Rakománynak az adatait
  -- EN - Get the package details
  --
  SELECT Code, ArticleCode, ArticleName, CAST(Expired as DATE) Expired, LocationCode, Quantity, UnitCode, N'' Notes
    FROM ZeusPackage
   WHERE Code = @Code
    
-- Well done.
--
  RETURN(0)

-- We have a problem !
--
__ERROR__:
  RETURN(1)
END
GO
